<?php
namespace Kuoqi\Api\Weixin\Mp;
use Kuoqi\Api\Weixin\Tools;
use Kuoqi\Api\Weixin\Config;
/**
 * 微信粉丝模块的基础接口等
 * Class Fans
 * @package Kuoqi\Api\Weixin\Mp
 */
class Fans{

    //授权成功的时候获取用户信息
    static $url_ahthuserinfo = 'https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s';

    //普通的
    static $url_userinfo = 'https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=%s';

    //获取粉丝列表
    static $url_list = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s';


    /**
     * 用户临时授权
     * @param string $openid
     * @param string $auth_token
     * @return array
     */
    public function getAuthUserinfo($openid = '',$auth_token = ''){
        $url = sprintf(self::$url_ahthuserinfo,
            $auth_token,
            $openid,
            'zh_CN'
        );
        $response = new response(tools::sendTo($url));
        return $response->toArray();
    }

    /**
     * 获取列表信息
     * @param string $openid 起始点的openid
     * @return array
     */
    public function getList($openid = ''){
        $url = sprintf(self::$url_list,
            Config::getAccessToken(),
            $openid
        );
        $response = new response(tools::sendTo($url));
        return $response->toArray();
    }

    /**
     * 获取微信粉丝信息
     * @param string $openid
     * @return array
     */
    public function getUserinfo($openid =''){
        $url = sprintf(self::$url_userinfo,
            Config::getAccessToken(),
            $openid,
            'zh_CN'
        );
        $response = new response(tools::sendTo($url));
        return $response->toArray();
    }
}